package com.cctc.rds.nrpc.core.server.handler;

import com.cctc.rds.nrpc.core.util.NrpcLogger;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateHandler;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class ServerIdleStateHandler extends IdleStateHandler {
    public ServerIdleStateHandler(long timeout) {
        super(0, 0, timeout, TimeUnit.MILLISECONDS);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        if (cause instanceof IOException) {
            NrpcLogger.getLogger().warn(cause.getMessage());
            return;
        } else {
            super.exceptionCaught(ctx, cause);
        }
    }
}
